var chess_board_aviable_min=0;
var box=0;
for (var create_array=0;create_array<15;create_array++)
{
	eval("var x"+create_array+"=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7];")
}
var x15=[7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7];

$(document).ready(function(){
	var chess_board_height=$(".chess_board").height();
	var chess_board_width=$(".chess_board").width();
	if (chess_board_height>=chess_board_width)
	{
		$(".chess_board").height(chess_board_width);
		var chess_board_min=chess_board_width;
	}
	else
	{
		$(".chess_board").width(chess_board_height);
		var chess_board_min=chess_board_height;
	}
	var chess_board_aviable_height=$(".chess_board_aviable").height();
	var chess_board_aviable_width=$(".chess_board_aviable").width();
	if (chess_board_aviable_height>=chess_board_aviable_width)
	{
		$(".chess_board_aviable").height(chess_board_aviable_width);
		chess_board_aviable_min=chess_board_aviable_width;
	}
	else
	{
		$(".chess_board_aviable").width(chess_board_aviable_height);
		chess_board_aviable_min=chess_board_aviable_height;
	}
	for (var x=0;x<=14;x++)
	{
		for (var y=0;y<=14;y++)
		{
			var box_top=y*6.666666667;
			var box_left=x*6.666666667;
			var div_text="<div onclick=\"play('"+x+"','"+y+"')\" id='box_"+x+"_"+y+"' style='transition:all 0.1s;transform:scale(0.9,0.9);position:absolute;top:"+box_top+"%;left:"+box_left+"%;border-radius:50%;width:6.666666667%;height:6.666666667%;'></div>";
			$("#board").append(div_text);
		}
	}
	for (var i=1;i<14;i++)
	{
		var box_=i*7.142857143;
		var div_text2="<div class='gez' style='position:absolute;top:0px;left:0px;width:"+box_+"%;height:100%'></div>";
		var div_text3="<div class='gez2' style='position:absolute;top:0px;left:0px;width:100%;height:"+box_+"%'></div>";
		$("#chess_board_aviable").append(div_text2);
		$("#chess_board_aviable").append(div_text3);
	}
})

window.onresize=function(){
	var chess_board_height=document.documentElement.clientHeight*0.88;
	var chess_board_width=document.documentElement.clientWidth*0.88;
	if (chess_board_height>=chess_board_width)
	{
		var chess_board_min=chess_board_width;
	}
	else
	{
		var chess_board_min=chess_board_height;
	}
	$(".chess_board").height(chess_board_min);
	$(".chess_board").width(chess_board_min);
	var chess_board_aviable_height=document.documentElement.clientHeight*0.825;
	var chess_board_aviable_width=document.documentElement.clientWidth*0.825;
	if (chess_board_aviable_height>=chess_board_aviable_width)
	{
		chess_board_aviable_min=chess_board_aviable_width;
	}
	else
	{
		chess_board_aviable_min=chess_board_aviable_height;
	}
	$(".chess_board_aviable").height(chess_board_aviable_min);
	$(".chess_board_aviable").width(chess_board_aviable_min);
}

var turn="black";
var x_2=0;
var y_2=0;
var times=0;
function play(x,y)
{
	x=parseInt(x);
	y=parseInt(y);
	if (eval("x"+x+"["+y+"]")==0 && msg_permission==1)
	{
		if (turn=="black")
		{
			if (times!=0)
				{document.getElementById("box_"+x_2+"_"+y_2).style.border="1px solid #aaa";}
			eval("x"+x+"["+y+"]='black'");
			document.getElementById("box_"+x+"_"+y).style.backgroundColor="black";
			document.getElementById("box_"+x+"_"+y).style.boxSizing="border-box";
			document.getElementById("box_"+x+"_"+y).style.border="1px solid #00cc47";
			document.getElementById("box_"+x+"_"+y).style.boxShadow="5px 5px 10px #ccc";
			turn="white";
		}
		else
		{
			document.getElementById("box_"+x_2+"_"+y_2).style.border="1px solid #000";
			eval("x"+x+"["+y+"]='white'");
			document.getElementById("box_"+x+"_"+y).style.backgroundColor="white";
			document.getElementById("box_"+x+"_"+y).style.boxSizing="border-box";
			document.getElementById("box_"+x+"_"+y).style.border="1px solid #00cc47";
			document.getElementById("box_"+x+"_"+y).style.boxShadow="5px 5px 10px #ccc";
			turn="black";
		}
		charge(x,y);
		x_2=x;
		y_2=y;
		times++;
	}
}

function charge(x,y)
{
	x=parseInt(x);
	y=parseInt(y);
	eval("var temp_color=x"+x+"["+y+"]");
	for (var create_p=1;create_p<=8;create_p++)
		{
			eval("p"+create_p+"=1");
		}
	for (var create_i=1;create_i<=4;create_i++)
	{
		eval("i"+create_i+"=0");
	}
	while (eval("x"+x+"["+(y+p1)+"]")==temp_color && (y+p1)<=14)
	{
		p1++;
		i1++;
	}
	while (eval("x"+x+"["+(y-p2)+"]")==temp_color && (y-p2)>=0)
	{
		p2++;
		i1++;
	}
	while (eval("x"+(x-p3)+"["+y+"]")==temp_color && (x-p3)>=0)
	{
		p3++;
		i2++;
	}
	if ((x+p4)<=14)
	{
		while (eval("x"+(x+p4)+"["+y+"]")==temp_color && (x+p4)<=14)
		{
			p4++;
			i2++;
		}
	}
	while (eval("x"+(x-p5)+"["+(y+p5)+"]")==temp_color && (x-p5)>=0 && (y+p5)<=14)
	{
		p5++;
		i3++;
	}
	if ((x+p6)<=14)
	{
		while (eval("x"+(x+p6)+"["+(y-p6)+"]")==temp_color && (x+p6)<=14 && (y-p6)>=0)
		{
			p6++;
			i3++;
		}
	}
	if ((x+p7)<=14)
	{
		while (eval("x"+(x+p7)+"["+(y+p7)+"]")==temp_color && (x+p7)<=14 && (y+p7)<=14)
		{
			p7++;
			i4++;
		}
	}
	while (eval("x"+(x-p8)+"["+(y-p8)+"]")==temp_color && (x-p8)>=0 && (y-p8)>=0)
	{
		p8++;
		i4++;
	}
	for (var z=1;z<=4;z++)
	{
		if(eval("i"+z)>=4)
		{
			if (temp_color=="black")
				{msg("黑方胜")}
			else
				{msg("白方胜")}
		}
	}
}

var msg_permission=1;
function msg(text)
{
	if (msg_permission==1)
	{
		$(".msg_box").css({"transform":"translate(-50%,-50%) scale(1,1)"});
		$("#text").text(text);
		if (text=="黑方胜")
		{
			$(".msg_box").css({
				"backgroundColor":"#000",
				"color":"white",
			});
		}
		msg_permission=0;
	}
}